<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <style>
        .el-table th {
            display: table-cell !important;
        }
    </style>
</head>

<body>
<div id="app">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">

        <el-form-item label="模块名称" prop="type">
            <el-input v-model="queryParams.name"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
    </el-form>

    <!--功能条-->
    <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
            <el-button
                    type="primary"
                    plain
                    icon="el-icon-plus"
                    size="mini"
                    @click="addRow"
            >新增</el-button>
        </el-col>
    </el-row>
    <el-table
            :data="tableData"
            style="width: 100%;height:100%"
            >
        <el-table-column
                fixed
                prop="id"
                label="模块ID"
                width="200">
        </el-table-column>
        <el-table-column
                prop="name"
                label="模块名称"
                width="250">
        </el-table-column>
        <el-table-column
                prop="key"
                label="key值"
                width="120">
        </el-table-column>
        <el-table-column
                prop="metaInfo"
                label="详细信息"
                width="400">
        </el-table-column>
        <el-table-column
                prop="lastUpdateTime"
                label="上次更新时间"
                width="300">
        </el-table-column>
        <el-table-column
                prop="createTime"
                label="创建时间"
                width="300">
        </el-table-column>

        <el-table-column

                label="操作"
                width="200">
            <template slot-scope="scope">
                <el-button
                        @click.native.prevent="deployRow(scope.$index, tableData)"
                        type="text"
                        size="small">
                    发布
                </el-button>
                <el-button
                        @click.native.prevent="editRow(scope.$index, tableData)"
                        type="text"
                        size="small">
                    编辑
                </el-button>
                    <el-button
                            @click.native.prevent="deleteRow(scope.$index, tableData)"
                            type="text"
                            size="small">
                        删除
                    </el-button>
                </template>

        </el-table-column>

    </el-table>
    <el-pagination
            style="float:right"
            @current-change="changePage"
            :current-page="pageNum"
            :page-sizes="[10, 20, 50, 100]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
    </el-pagination>
    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog  :visible.sync="open" width="500px" append-to-body>
        <el-form ref="form" :model="form"  label-width="80px">

            <el-form-item label="模型KEY" prop="key">
                <el-input v-model="form.key" placeholder="请输入模型KEY" />
            </el-form-item>
            <el-form-item label="模型名称" prop="name">
                <el-input v-model="form.name" placeholder="请输入模型名称" />
            </el-form-item>
            <el-form-item label="模型描述" prop="description">
                <el-input v-model="form.description" placeholder="请输入模型描述" />
            </el-form-item>

        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button type="primary" @click="submitForm">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
</div>
</body>
<!-- import Vue before Element -->
<script  src="js/axios.js"></script>
<script  src="js/vue.js"></script>
<script   src="js/elementui.js"></script>
<script>
    new Vue({
        el: '#app',

        created(){
            this.getList();
        },
        data() {
            return {
                form:{},
                open:false,
                queryParams:{
                    name:""
                },
                pageSize:10,
                pageNum:1,

                showSearch:true,
                tableData: [],
                total:0,
            }
        },
        methods: {
            submitForm(){
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.id != null) {

                        } else {
                            axios.post(`/activiti/create`,this.form).then(response => {
                                if(response.data.success){
                                    this.$message({message:'新增成功!',type:'success'});
                                    this.getList();
                                    this.open=false;
                                }else{
                                    this.$message({message:'新增失败!',type:'warning'});
                                }
                            }).catch(error => {
                                this.$message({message:'新增异常!',type:'error'});

                            })
                        }
                    }
                });
           },
             cancel(){
                 this.open=false;
             },
            changePage(page){
                 this.pageNum=page;
                 this.getList();
            },
            addRow(){
                 this.open=true;
            },
            editRow(index, rows) {
               window.location.href='http://localhost:8090/modeler.html?modelId='+rows[index].id;
            },
             deployRow(index, rows) {

                this.$confirm('是否确认发布模型ID为"' + rows[index].id + '"的数据项?', "警告", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(()=> {
                   this.deploy(rows[index].id);
                }).catch(() => {});

            } ,
            deleteRow(index, rows) {

                this.$confirm('是否确认删除模型ID为"' + rows[index].id + '"的数据项?', "警告", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(()=> {
                   this.delete (rows[index].id);
                }).catch(() => {});

            },
            deploy(id){
                axios.get(`/activiti/deploy/${id}`).then(response => {
                    if(response.data.success){
                        this.$message({
                            message: "发布成功!",
                            type: 'success'
                        });
                        this.getList();
                    }else{
                        this.$message({
                            message: "发布失败!",
                            type: 'warning'
                        });
                    }

                }).catch(error => {
                    this.$message({
                        message: "操作异常",
                        type: 'error'
                    });

                })
            },
            delete(id){
                axios.get(`/activiti/delete/${id}`).then(response => {
                    this.$message({
                        message: response.data,
                        type: 'success'
                    });
                    this.getList();
                }).catch(error => {
                    this.$message({
                        message: "操作异常",
                        type: 'error'
                    });
                })
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.queryParams={};
               this.getList();
            },
            getList(){
                axios.post(`/mybatisplus/act-re-model/selectList`,
                    {
                        pageSize:this.pageSize,
                        pageNum:this.pageNum,
                        name:this.queryParams.name

                    }).then(response => {
                    this.tableData = response.data.queryResult.list;
                    this.total=response.data.queryResult.total;
                })
            }
        },
    })
</script>
</html>
